<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

		<title>购物车页面</title>

		<link href="${pageContext.request.contextPath }/AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css" />
		<link href="${pageContext.request.contextPath }/basic/css/demo.css" rel="stylesheet" type="text/css" />
		<link href="${pageContext.request.contextPath }/css/cartstyle.css" rel="stylesheet" type="text/css" />
		<link href="${pageContext.request.contextPath }/css/optstyle.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.7.2.min.js"></script>
		<script type="text/javascript"> 
			$(function(){ 
				
				$(".add*").click(function(){ 
					var t=$(this).parent().find('input[class=text_box]'); 
					confirm("确定增加商品？");
					t.val(parseInt(t.val())+1) 
					var pid = t.attr("name");
					commit(pid, parseInt(t.val()), t);
				}) 
				
				$(".min*").click(function(){ 
					var t=$(this).parent().find('input[class=text_box]'); 
					if(parseInt(t.val())==1){ 
						confirm("已是商品最少数量");
						return;
					} 
					t.val(parseInt(t.val())-1);
					confirm("确定减少商品？");
				}) 

				function commit(pid, count, t){
					var url = "${pageContext.request.contextPath }/cart_addOrSubCart.action";
					var args = {"pid": pid, "count":count, "time":new Date()};
					
					$.post(url, args, function(data){
						var d = eval("("+data+")");
						var ST = d.subTotal;
						alert(ST);
						var i = t.attr("title");
						alert(i);
						
						//var a = $("#i").text("123");
						//var str = a.valueOf();
						//alert(str);
						//var a = $("#i");
						//a.text(ST);
						document.getElementById(i).innerText = ST;
						
					},"JSON");
				//	$.getJSON(url, args, function(data){
				//		var d = eval("("+data+")");
				//		alert(d.subTotal);
				//	});
				}
			
				function setTotal(){ 
					var s=0; 
					
					$("#tab td").each(function(){ 
						s+=parseInt($(this).find('input[class*=text_box]').val())*parseFloat($(this).find('span[class*=price]').text()); 
					}); 
					
					$("#total").html(s.toFixed(2)); 
				} 
				setTotal(); 
			}) 
		</script> 

	</head>

	<body>

		<!--顶部导航条 -->
		<%@ include file="menu.jsp" %>

			<!--悬浮搜索框-->

			<%@ include file="find.jsp" %>

			<div class="clear"></div>

			<!--购物车 -->
			<div class="concent">
				<div id="cartTable">
				<s:if test="#session.cart.cartItems.size() != 0">
					<div class="cart-table-th">
						<div class="wp">
							<div class="th th-chk">
								<div id="J_SelectAll1" class="select-all J_SelectAll">

								</div>
							</div>
							<div class="th th-item">
								<div class="td-inner">商品信息</div>
							</div>
							<div class="th th-price">
								<div class="td-inner">单价</div>
							</div>
							<div class="th th-amount">
								<div class="td-inner">数量</div>
							</div>
							<div class="th th-sum">
								<div class="td-inner">金额</div>
							</div>
							<div class="th th-op">
								<div class="td-inner">操作</div>
							</div>
						</div>
					</div>
					<div class="clear"></div>

					<s:iterator var="cartItem" value="#session.cart.cartItems" status="status"><tr class="item-list"><div class="bundle  bundle-last ">
					<s:if test="#session.existUser == null">
						<div class="bundle-hd"><div class="bd-promos">已享优惠:
						<a href="${pageContext.request.contextPath }/user_loginPage.action"><font color="green">登录后确认是否享有优惠</font></a>
						</div></div>
					</s:if>
					<s:else>
						<div class="bundle-hd">
							<div class="bd-promos">
								<div class="bd-has-promo">已享优惠:<span class="bd-has-promo-content">省￥19.50</span>&nbsp;&nbsp;</div>
								<div class="act-promo">
									<a href="#" target="_blank">第二支半价，第三支免费<span class="gt">&gt;&gt;</span></a>
								</div>
								<span class="list-change theme-login">编辑</span>
							</div>
						</div>
					</s:else>
					<div class="clear"></div>
					<div class="bundle-main">
						<ul class="item-content clearfix">
							<li class="td td-chk">
								<div class="cart-checkbox ">
									<input class="check" id="J_CheckBox_170037950254" name="items[]" value="170037950254" type="checkbox">
									<label for="J_CheckBox_170037950254"></label>
								</div>
							</li>
							<li class="td td-item">
								<div class="item-pic">
								<s:iterator var="image" value="#cartItem.product.images">
									<s:if test="#image.idesc == 1">
									<a href="${pageContext.request.contextPath }/product_findByPid.action?pid=<s:property value="#cartItem.product.pid"/>" target="_blank" data-title="<s:property value="#cartItem.product.pname"/>" class="J_MakePoint" data-point="tbcart.8.12">
										<img src="${pageContext.request.contextPath }/<s:property value="#image.uri_small"/>" class="itempic J_ItemImg"></a>
									</s:if>
								</s:iterator>
								</div>
								<div class="item-info">
									<div class="item-basic-info">
										<a href="${pageContext.request.contextPath }/product_findByPid.action?pid=<s:property value="#cartItem.product.pid"/>" target="_blank" title="<s:property value="#cartItem.product.pname"/>" class="item-title J_MakePoint" data-point="tbcart.8.11"><s:property value="#cartItem.product.pname"/></a>
									</div>
								</div>
							</li>
							<li class="td td-info">
								<div class="item-props item-props-can">
									<span class="sku-line">颜色：12#川南玛瑙</span>
									<span class="sku-line">包装：裸装</span>
									<span tabindex="0" class="btn-edit-sku theme-login">修改</span>
									<i class="theme-login am-icon-sort-desc"></i>
								</div>
							</li>
							<li class="td td-price">
								<div class="item-price price-promo-promo">
									<div class="price-content">
										<div class="price-line">
											<em class="price-original"><s:property value="#cartItem.product.shop_price"/></em>
										</div>
										<div class="price-line">
											<em class="J_Price price-now" tabindex="0"><s:property value="#cartItem.product.act_price"/></em>
										</div>
									</div>
								</div>
							</li>
							<li class="td td-amount">
								<div class="amount-wrapper ">
									<div class="item-amount ">
										<div class="sl">
											<input class="min am-btn" name="sub" id="sub" type="button" value="-" />
											<input class="text_box" name=<s:property value="#cartItem.product.pid"/> 
												title="<s:property value="#status.count"/>" type="text" value="<s:property value="#cartItem.count"/>" 
													style="width:30px;" />
											<input class="add am-btn" name="add" id="add" type="button" value="+" />
										</div>
									</div>
								</div>
							</li>
							<li class="td td-sum">
								<div class="td-inner">
									<em tabindex="0" class="J_ItemSum number" name="subTotal" >
										<span  id="<s:property value="#status.count"/>"><s:property value="#cartItem.subtotal"/></span>
									</em>
								</div>
							</li>
							<li class="td td-op">
								<div class="td-inner">
									<a title="移入收藏夹" class="btn-fav" href="#"> 移入收藏夹</a>
									<a href="${pageContext.request.contextPath }/cart_removeCart.action?pid=<s:property value="#cartItem.product.pid"/>" data-point-url="#" class="delete"> 删除</a>
								</div>
							</li>
						</ul>
					</div>
					</div></tr></s:iterator>
					<div class="clear"></div>
			</s:if>
			<s:else>
				<center>
					<div class="span24">
							<img src="${pageContext.request.contextPath }/images/emptyCart.png"/>
							<span><h2>您的购物车还是空的，赶紧行动吧！</h2></span>
					</div>
				</center>
			</s:else>
				</div>
				<div class="clear"></div>

				<div class="float-bar-wrapper">
					<div id="J_SelectAll2" class="select-all J_SelectAll">
						<div class="cart-checkbox">
							<input class="check-all check" id="J_SelectAllCbx2" name="select-all" value="true" type="checkbox">
							<label for="J_SelectAllCbx2"></label>
						</div>
						<span>全选</span>
					</div>
					<div class="operations">
						<a href="${pageContext.request.contextPath }/cart_clearCart.action" hidefocus="true" class="deleteAll">删除</a>
						<a href="#" hidefocus="true" class="J_BatchFav">移入收藏夹</a>
					</div>
					<div class="float-bar-right">
						<div class="amount-sum">
							<span class="txt">已选商品</span>
							<em id="J_SelectedItemsCount">0</em><span class="txt">件</span>
							<div class="arrow-box">
								<span class="selected-items-arrow"></span>
								<span class="arrow"></span>
							</div>
						</div>
						<div class="price-sum">
							<span class="txt">合计:</span>
							<strong class="price">¥<em id="J_Total"><s:property value="#session.cart.total"/></em></strong>
						</div>
						<div class="btn-area">
							<a href="${pageContext.request.contextPath }/order_save.action" id="J_Go" class="submit-btn submit-btn-disabled" aria-label="请注意如果没有选择宝贝，将无法结算">
								<span>结&nbsp;算</span></a>
						</div>
					</div>

				</div>
				<%@ include file="floor.jsp" %>
			</div>
			
		<!--引导 -->	
		<%@ include file="guide.jsp" %>
	</body>

</html>